import jwt
import datetime
from django.conf import settings


class JWTTool:
    def getToken(self, userid, account):
        data = {
            'userid': userid,
            'account': account,
            'exp': datetime.datetime.now() + datetime.timedelta(hours=1)
        }
        return 'Bearer ' + jwt.encode(payload=data, key=settings.SECRET_KEY)

    def checkToken(self, token):
        return jwt.decode(token, key=settings.SECRET_KEY, algorithms='HS256')


tooljwt = JWTTool()
# print(tool.getToken(1, 'admin'))
# print(tool.checkToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsImFjY291bnQiOiJhZG1pbiIsImV4cCI6MTczNDk1NzQxNH0.4wJpDvY4zmrSItXjLEI3xQx43MOmfa-O5yLTWbSBMj4'))
